package com.meng.menggaga.protocol;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.meng.menggaga.application.MainApplication;
import com.meng.menggaga.entity.CommunityCategoryInfos;
import com.meng.menggaga.entity.CommunityDetailInfos;
import com.meng.menggaga.entity.CommunityInfos;
import com.meng.menggaga.entity.UserInfo;
import com.meng.menggaga.protocol.model.CommunityCategoryRequest;
import com.meng.menggaga.protocol.model.CommunityDetailInfoRequest;
import com.meng.menggaga.protocol.model.CommunityDetailLayerInfosRequest;
import com.meng.menggaga.protocol.model.CommunityListRequest;

public class MoccaApiImpl implements MoccaApi {
	private final RequestQueue requestQueue = MainApplication.get()
			.getRequestQueue();

	@Override
	public Request<?> getCommunityCategory(String fup,
			Listener<CommunityCategoryInfos> listener,
			ErrorListener errorListener) {
		CommunityCategoryRequest request = new CommunityCategoryRequest(
				getBaseUrl(ACTION_COMMUNITY_CATEGORY_LIST), listener,
				errorListener);
		request.addParams(PARAM_FUP, fup);
		return requestQueue.add(request);
	}

	@Override
	public Request<?> getCommunityList(int fid, int page, int pageSize,
			Listener<CommunityInfos> listener, ErrorListener errorListener) {
		CommunityListRequest request = new CommunityListRequest(
				getBaseUrl(ACTION_COMMUNITY_LIST), listener, errorListener);
		request.addParams(PARAM_FID, fid);
		request.addParams(PARAM_PAGE, page);
		request.addParams(PARAM_PAGE_SIZE, pageSize);
		return requestQueue.add(request);
	}

	@Override
	public Request<?> login(String username, String password,
			Listener<UserInfo> listener, ErrorListener errorListener) {
		// CommunityDetailLayerInfosRequest request =
		// new CommunityDetailLayerInfosRequest(
		// getBaseUrl(ACTION_COMMUNITY_LIST_ITEM_DETAIL_LAYER), listener,
		// errorListener);
		// request.addParams(PARAM_ACTION, ACTION_COMMUNITY_LIST_ITEM_DETAIL);
		// request.addParams(PARAM_TID, tid);
		return null;
	}

	@Override
	public Request<?> getCommunityDetailInfos(String tid, int page,
			int pageSize, Listener<CommunityDetailInfos> listener,
			ErrorListener errorListener) {
		CommunityDetailInfoRequest request = new CommunityDetailInfoRequest(
				getBaseUrl(ACTION_COMMUNITY_DETAIL), listener, errorListener);
		request.addParams(PARAM_ACTION, ACTION_COMMUNITY_DETAIL);
		request.addParams(PARAM_TID, tid);
		request.addParams(PARAM_PAGE, page);
		request.addParams(PARAM_PAGE_SIZE, pageSize);
		return requestQueue.add(request);
	}

	@Override
	public Request<?> getCommunityDetailLayerInfos(String tid,
			Listener<CommunityDetailInfos> listener, ErrorListener errorListener) {
		CommunityDetailLayerInfosRequest request = new CommunityDetailLayerInfosRequest(
				getBaseUrl(ACTION_COMMUNITY_DETAIL_LAYER), listener,
				errorListener);
		request.addParams(PARAM_ACTION, ACTION_COMMUNITY_DETAIL);
		request.addParams(PARAM_TID, tid);
		return requestQueue.add(request);
	}

	private String getBaseUrl(String page) {
		return BASEURL + page;
	}

	@Override
	public Request<?> checkUpdate(Listener<Boolean> listener,
			ErrorListener errorListener) {
		// TODO Auto-generated method stub
		return null;
	}

}
